Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports SistemaControlTraficoLibBusiness
Imports SistemaControlTraficoLibDS

<WebService(Namespace:="http://tempuri.org/"), _
 WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1), _
 System.Web.Script.Services.ScriptService()> _
Public Class AutoComplete
    Inherits WebService
    Private _Calle As New boCalle()
    Private _Cliente As New boCliente()

    Public Sub New()
        MyBase.New()
    End Sub

    <WebMethod()> _
    Public Function GetCalles(ByVal prefixText As String, ByVal count As Integer) As String()
        If (count = 0) Then
            count = 10
        End If

        Dim ds As System.Data.DataSet = _Calle.FindByTexto(prefixText)
        Dim filas As Integer = ds.Tables("Calle").Rows.Count()

        Dim random As Random = New Random
        Dim items As List(Of String) = New List(Of String)(count)

        Dim i As Integer = 0
        Dim a As Integer = 0
        Do While (i < count)
            Do While (a < filas)
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(
                    ds.Tables("Calle").Rows(a).Item("CalleNombre").ToString(),
                    ds.Tables("Calle").Rows(a).Item("CalleID").ToString()))

                a = (a + 1)
            Loop

            i = (i + 1)
        Loop

        Return items.ToArray
    End Function
    <WebMethod()> _
    Public Function GetCallesByPartido(ByVal prefixText As String, ByVal partidoID As Integer, ByVal count As Integer) As String()
        If (count = 0) Then
            count = 10
        End If

        Dim ds As System.Data.DataSet = _Calle.FindByPartidoNombre(partidoID, prefixText)
        Dim filas As Integer = ds.Tables("Calle").Rows.Count()

        Dim random As Random = New Random
        Dim items As List(Of String) = New List(Of String)(count)

        Dim i As Integer = 0
        Dim a As Integer = 0
        Do While (i < count)
            Do While (a < filas)
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(
                    ds.Tables("Calle").Rows(a).Item("CalleNombre").ToString(),
                    ds.Tables("Calle").Rows(a).Item("CalleID").ToString()))

                a = (a + 1)
            Loop

            i = (i + 1)
        Loop

        Return items.ToArray
    End Function
    <WebMethod()> _
    Public Function GetClientes(ByVal prefixText As String, ByVal count As Integer) As String()
        If (count = 0) Then
            count = 10
        End If

        Dim ds As System.Data.DataSet = _Cliente.FindByTexto(prefixText)
        Dim filas As Integer = ds.Tables("Cliente").Rows.Count()

        Dim random As Random = New Random
        Dim items As List(Of String) = New List(Of String)(count)

        Dim i As Integer = 0
        Dim a As Integer = 0
        Do While (i < count)
            Do While (a < filas)
                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(
                    ds.Tables("Cliente").Rows(a).Item("ClienteRazonSocial").ToString(),
                    ds.Tables("Cliente").Rows(a).Item("ClienteID").ToString()))

                a = (a + 1)
            Loop

            i = (i + 1)
        Loop

        Return items.ToArray
    End Function
End Class

